package com.luntan.controller;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.luntan.bean.User;
import com.luntan.mapper.UserMapper;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author jw课程设计
 * @since 2022-07-12
 */
@CrossOrigin
@RestController
@RequestMapping("/user")
public class UserController {

    @Autowired
    UserMapper userMapper;


    @ApiOperation("用户登录")
    @PostMapping("login")
    public User login(@RequestBody User user1){
        System.out.println("niyayayya");
        System.out.println(user1);
        String username = user1.getUsername();
        String password = user1.getPassword();
        QueryWrapper<User> wrapper = new QueryWrapper<>();
        wrapper
                .eq("username",username)
                .eq("password",password);
        User user = userMapper.selectOne(wrapper);
        if(user!=null){
            return user;
        }
        return null;
    }

    @ApiOperation("用户注册")
    @PostMapping("registor")
    public String registor(@RequestBody User user){
        int result = userMapper.insert(user);
        if(result>=1){
            return "插入成功";
        }else {
            return "插入失败";
        }
    }


//    @ApiOperation("按用户名查询用户")
//    @PostMapping("getUserByName")

//    @ApiOperation("添加用户")
//    @PostMapping("addUser")


//    @ApiOperation("修改用户信息")
//    @PostMapping("updateUser")

//    @ApiOperation("删除用户信息")
//    @PostMapping("deleteUser")

}

